﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace homework2
{
    public partial class task2 : Form
    {
        public task2()
        {
            InitializeComponent();
        }

        private bool isPrime(int number)
        {
            if(number <= 1)
                return false;
            for(int i = 2; i <= Math.Sqrt(number); i++) 
            { 
                if (number % i == 0)
                    return false;
            }
            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int lowerBound, upperBound;
            if (!int.TryParse(textBox1.Text, out lowerBound) || !int.TryParse(textBox2.Text, out upperBound)||lowerBound>upperBound||lowerBound<0||upperBound<0)
            {
                MessageBox.Show("请输入有效的非负整数，且下限应小于等于上限");
                return;
            }

            label4.Text = "";

            int count = 0;
            for (int i = lowerBound; i <= upperBound; i++)
            {
                if (isPrime(i))
                {
                    label4.Text += i + " ";
                    count++;
                    if (count % 10 == 0)
                        label4.Text += "\n";
                }
            }
        }
    }
}
